import dayjs from 'dayjs';

export function l2m(list: any[], labelKey: string, valueKey?: string): any {
  const obj = {};
  list.forEach(item => {
    obj[item[labelKey]] = valueKey ? item[valueKey] : item;
  });
  return obj;
}

export function l2ArrMap(list: any[], labelKey: string, valueKey?: string): any {
  const obj = {};
  list.forEach(item => {
    obj[item[labelKey]] ??= [];
    obj[item[labelKey]].push(valueKey ? item[valueKey] : item);
  });
  return obj;
}
export function formatDate(date): string {
  if (date) {
    return dayjs(date).format('YYYY-MM-DD');
  } else {
    return '';
  }
}
